1
Mechanics of the Method Call
AI035 Lesson 13
00:00

In Ruby, a method call is not a static jump to a memory address; it is a dynamic Message-Passing event. When you invoke a method, you are sending a message to a Receiver. This message consists of the method name, optional arguments, and a potential Block Association.

1. Call Syntax & Ambiguity

Ruby allows great flexibility: Foo.Bar and Foo.Bar() are identical. However, Foo::Bar usually refers to a constant, while Foo::Bar() forces a method call. Parentheses are often omitted to create DSL-like experiences where methods look like properties.

2. Operator Deconstruction

Operators are actually Redefinable Methods. The expression expr1 + expr2 is sugar for (expr1).+(expr2). This applies to unary (-obj), binary (a < b), and suffix operators.

ReceiverMessage (Method)Block Sidecaryield control

3. The yield Mechanism

Methods use yield to push control flow into the associated block. Using Kernel.block_given?, a method can dynamically decide how to handle logic based on the caller’s context.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>